package cn.kgc.qnbbs.controller;

import cn.kgc.qnbbs.pojo.Detail;
import cn.kgc.qnbbs.pojo.ResultEntity;
import cn.kgc.qnbbs.pojo.Sort;
import cn.kgc.qnbbs.service.DetailService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
public class DetailController {
    @Resource
    DetailService detailService;

    @RequestMapping("/selectDetail")
    public ResultEntity<List<Detail>> selectDetail(@RequestParam (value = "sortid",defaultValue = "0")Integer sortid){
        List<Detail> detailList = detailService.selectAll(sortid);
        return ResultEntity.successWithoutData(detailList);
    }

    @RequestMapping("/getSort")
    public  ResultEntity<List<Sort>> getSort(){
        List<Sort> sortList = detailService.selectAllSort();
        return ResultEntity.successWithoutData(sortList);
    }
    @RequestMapping("/saveDetail")
    public  ResultEntity<Integer> saveDetail(@RequestBody Detail detail){
        detail.setCreatedate(new Date());
        detail.setReplycount(0);
        Integer saveDetail = detailService.saveDetail(detail);
        return ResultEntity.successWithoutData(saveDetail);
    }
}
